package com.carcenter.order.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carcenter.common.result.enums.impl.RedisConst;
import com.carcenter.order.entity.CarBrands;
import com.carcenter.order.entity.ProductBrands;
import com.carcenter.order.mapper.ProductBrandsMapper;
import com.carcenter.order.service.IProductBrandsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author car
 * @since 2025-07-16
 */
@Service
public class ProductBrandsServiceImpl extends ServiceImpl<ProductBrandsMapper, ProductBrands> implements IProductBrandsService {
    @Autowired
    private ProductBrandsMapper productBrandsMapper;

    @Override
    @Cacheable(cacheNames = RedisConst.PRODUCT_BRANDS_LIST, keyGenerator = "keyGenerator")
    public Page<ProductBrands> getProductDetail(Integer pageNum, Integer pageSize) {
        Page<ProductBrands> page = new Page<>(pageNum,pageSize);
        return productBrandsMapper.selectPage(page,null);
    }

    @Override
    @CacheEvict(cacheNames = RedisConst.PRODUCT_BRANDS_LIST, allEntries = true)
    public void add(ProductBrands productBrands) {
        this.save(productBrands);
    }

    @Override
    @CacheEvict(cacheNames = RedisConst.PRODUCT_BRANDS_LIST, allEntries = true)
    public void updateProduct(ProductBrands productBrands) {
        this.updateById(productBrands);
    }

    @Override
    @CacheEvict(cacheNames = RedisConst.PRODUCT_BRANDS_LIST, allEntries = true)
    public void removeProduct(Integer id) {
        this.removeById(id);
    }
}
